package com.ux.util
{
	import flash.display.DisplayObject;
	import flash.display.DisplayObjectContainer;
	import flash.display.MovieClip;
	
	/**
	 * @author winnie
	 */	
	public class DisplayObjUtil
	{
		
		/**
		 * 
		 * @param _name 가져오고자 하는 오브젝트의 name
		 * @param container 오브젝트 parent
		 * @param weakRef 단순 포함일 경우 true, 이름이 완전 일치일 경우 false
		 * @return 
		 * 
		 */		
		public static function getDisObjByName( _name:String, container:DisplayObjectContainer, weakRef:Boolean=true ):DisplayObject
		{
			var len:int = container.numChildren;
			for (var i:int = 0; i < len; i++) 
			{
				if( container.getChildAt( i ) == null ) continue;
				
				if( weakRef )
				{
					if( StringUtils.contains( container.getChildAt( i ).name, _name ) ) return container.getChildAt( i );
				}
				else
				{
					if( _name, StringUtils.similarity( container.getChildAt( i ).name, _name ) == 100 ) return container.getChildAt( i );
				}
			}
			
			return null;
		}
		
		
		/**
		 * 
		 * @param container 컨테이너
		 * @param instanceName 비교 인스턴스 네임
		 * @param listObj 갯수가 정해지지 않은 vector
		 * 
		 */		
		public static function makeList( container : DisplayObjectContainer, instanceName : String, listObj:Object ):void
		{
			var len:int = container.numChildren;;
			for (var i:int = 0; i < len; i++) 
			{
				if( container.getChildAt(i) == null ) continue;
				
				if( StringUtils.contains( container.getChildAt(i).name, instanceName ) == true )
				{
					listObj.push( container.getChildAt(i) );
				}
			}
		}
		
		/**
		 * 
		 * @param container 컨테이너
		 * @param instanceName 비교 인스턴스네임
		 * @param listObj 갯수가 정해져있는 vector 
		 * 
		 */		
		public static function makeListToLastNameSort( container : DisplayObjectContainer, instanceName : String, listObj:Object ):void
		{
			var len:int = container.numChildren;;
			for (var i:int = 0; i < len; i++) 
			{
				if( container.getChildAt(i) == null ) continue;
				
				if( StringUtils.contains( container.getChildAt(i).name, instanceName ) == true )
				{
					var idx : int = int( StringUtils.afterLast( container.getChildAt(i).name, instanceName ) );
					listObj[ idx ] = container.getChildAt(i);
				}
			}
		}
		
		
		
		public function DisplayObjUtil()
		{
		}
	}
}